package com.gaofei.controller;

import com.gaofei.common.LockUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : gaofee
 * @date : 14:06 2021/1/28
 * @码云地址 : https://gitee.com/itgaofee
 */
@RestController
public class TestRedission {

    static final String KEY = "LOCK_KEY";

    @GetMapping("/test")
    public Object test(){
        //加锁
        LockUtil.lock(KEY);
        try {
            //在这里就能保证线程安全,而且是分布式架构下的线程安全
            System.out.println(" 处理业务。。。");
        } catch (Exception e) {
            //异常处理
        }finally{
            //释放锁
            LockUtil.unlock(KEY);
        }

        return "SUCCESS";
    }

}
